package io.demo.message.benchmark;

import io.demo.message.serial.SerializedObject;
import java.io.Serializable;
import java.util.function.Function;
import java.util.stream.IntStream;

/**
 * @author lijinting01
 */
public abstract class AbstractBenchmark implements Benchmark {

  protected abstract <T extends Serializable> Function<T, SerializedObject<T>> serializer();

  @Override
  public void execute(Serializable o, int looping) {
    if (looping < 1) {
      throw new IllegalArgumentException("Loop Times");
    }
    IntStream.range(0, looping).forEach(i -> serializer().apply(o));
  }
}
